package com.ruoyi.zsyh.controller;

import java.util.List;

import com.ruoyi.zsyh.domain.ZsyhPlatformPartsattribute;
import com.ruoyi.zsyh.domain.ZsyhPlatformSellPartsAttribute;
import com.ruoyi.zsyh.service.IZsyhPlatformSellPartsAttributeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhPlatformSellparts;
import com.ruoyi.zsyh.service.IZsyhPlatformSellpartsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商城零售配件信息Controller
 * 
 * @author yuexl
 * @date 2025-04-27
 */
@Controller
@RequestMapping("/zsyh/sellParts")
public class ZsyhPlatformSellpartsController extends BaseController
{
    private String prefix = "zsyh/sellParts";

    @Autowired
    private IZsyhPlatformSellpartsService zsyhPlatformSellpartsService;
    @Autowired
    private IZsyhPlatformSellPartsAttributeService zsyhPlatformSellPartsAttributeService;

    @RequiresPermissions("zsyh:sellParts:view")
    @GetMapping()
    public String sellParts()
    {
        return prefix + "/sellParts";
    }

    /**
     * 查询商城零售配件信息列表
     */
    @RequiresPermissions("zsyh:sellParts:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhPlatformSellparts zsyhPlatformSellparts)
    {
        startPage();
        List<ZsyhPlatformSellparts> list = zsyhPlatformSellpartsService.selectZsyhPlatformSellpartsList(zsyhPlatformSellparts);
        return getDataTable(list);
    }

    /**
     * 查询产品规格列表
     */
    @RequiresPermissions("zsyh:sellParts:list")
    @PostMapping("/listChild")
    @ResponseBody
    public TableDataInfo listChild(String mid)
    {
        startPage();
        ZsyhPlatformSellPartsAttribute zsyhPlatformSellPartsAttribute = new ZsyhPlatformSellPartsAttribute();
        zsyhPlatformSellPartsAttribute.setPartsId(mid);
        List<ZsyhPlatformSellPartsAttribute> list = zsyhPlatformSellPartsAttributeService.selectZsyhPlatformSellPartsAttributeList(zsyhPlatformSellPartsAttribute);
        return getDataTable(list);
    }

    /**
     * 导出商城零售配件信息列表
     */
    @RequiresPermissions("zsyh:sellParts:export")
    @Log(title = "商城零售配件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhPlatformSellparts zsyhPlatformSellparts)
    {
        List<ZsyhPlatformSellparts> list = zsyhPlatformSellpartsService.selectZsyhPlatformSellpartsList(zsyhPlatformSellparts);
        ExcelUtil<ZsyhPlatformSellparts> util = new ExcelUtil<ZsyhPlatformSellparts>(ZsyhPlatformSellparts.class);
        return util.exportExcel(list, "商城零售配件信息数据");
    }

    /**
     * 新增商城零售配件信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商城零售配件信息
     */
    @RequiresPermissions("zsyh:sellParts:add")
    @Log(title = "商城零售配件信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhPlatformSellparts zsyhPlatformSellparts)
    {
        return toAjax(zsyhPlatformSellpartsService.insertZsyhPlatformSellparts(zsyhPlatformSellparts));
    }

    /**
     * 修改商城零售配件信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhPlatformSellparts zsyhPlatformSellparts = zsyhPlatformSellpartsService.selectZsyhPlatformSellpartsById(id);
        mmap.put("zsyhPlatformSellparts", zsyhPlatformSellparts);
        return prefix + "/edit";
    }

    /**
     * 修改保存商城零售配件信息
     */
    @RequiresPermissions("zsyh:sellParts:edit")
    @Log(title = "商城零售配件信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhPlatformSellparts zsyhPlatformSellparts)
    {
        return toAjax(zsyhPlatformSellpartsService.updateZsyhPlatformSellparts(zsyhPlatformSellparts));
    }

    /**
     * 删除商城零售配件信息
     */
    @RequiresPermissions("zsyh:sellParts:remove")
    @Log(title = "商城零售配件信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhPlatformSellpartsService.deleteZsyhPlatformSellpartsByIds(ids));
    }
}
